package com.tianshi.pxx.mapper;


import com.tianshi.pxx.pojo.entity.Cart;
import com.tianshi.pxx.pojo.vo.ProductVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CartMapper {
    @Select("select * from cart where product_id=#{productId} and user_id = #{userId}")
    Cart selectByProductIdAndUserId( @Param("productId") Integer productId,@Param("userId") Integer userId);

    @Insert("insert into cart(product_id, user_id,count) values(#{productId},#{userId},#{count})")
    Integer insert(Cart cart);

    /*
    * 修改购物车中商品数量
    * */
    @Update("update cart set count = #{count} where product_id = #{productId} and user_id = #{userId}")
    Integer update(Cart cart);


    @Select("select c.id as id,p.name as name,p.price as price,c.count as count from cart c,product p where c.product_id=p.id and c.user_id=#{userId}")
    List<ProductVO> selectProductVOByUserId(Integer userId);


    /*
    * 根据购物车id删除商品
    * */
    @Delete("delete from cart where id = #{id}")
    void delete(Integer id);


    @Delete("delete from cart where user_id = #{userId}")
    void deleteByUserId(Integer userId);


    @Select("select * from cart where id = #{id}")
    Cart selectById(Integer id);

    @Select("select product_id from cart where user_id = #{userId}")
    List<Integer> selectProductIdByUserId(Integer userId);
}
